<?php
namespace App\Query;

use App\Model\UserPay;
use App\Query\Traits\UserTrait;

class UserPayQuery extends \HyperfStore\Query
{
    use UserTrait;
    
    // 构建模型
    protected static function build()
    {
        return UserPay::latest();
    }

    // 渴望加载
    protected static function with()
    {
        return ['user', 'shop'];
    }
    
    // 时间区间
    protected static function queryTime($model, $where)
    {
        return $model->whereBetween('created_at', $where);
    }
    
    // 支付成功的
    public static function statusOk($model = null)
    {
        return static::model($model)->where('status', UserPay::STATUS_OK);
    }
    
    // 未支付
    public static function statusPost($model = null)
    {
        return static::model($model)->where('status', UserPay::STATUS_POST);
    }

    // 查询业绩
    public static function totalMoney($time, $model = null)
    {
        return static::statusOk(
            static::queryTime(static::model($model), $time)
        )->sum('money');
    }
}